/**
 * 
 * 
 * Date   21/07/2010      Intervenant Fewzi MOKADDEM  MICROPOLE
 */

Ext.onReady(function(){


	var login = new Ext.FormPanel({
		labelWidth:80,
		url:'j_spring_security_check',
		frame:true,
		title:'Authentification',

		defaultType:'textfield',
		width:300,
		height:150,
		monitorValid:true,
        //attributs specifique 
		items:[{
			fieldLabel:'Utilisateur',
			name:'j_username',
			allowBlank:false,
			msgTarget:'side',
			blankText:'Le nom d\'utilisateur est obligatoire !'
		},{
			fieldLabel:'Mot de passe',

			name:'j_password',
			inputType:'password',
			allowBlank:false,
			msgTarget:'side',
			blankText:'Le mot de passe est obligatoire !'
		}],


		buttons:[{

			text:'Se connecter',
			formBind: true,
			// Function that fires when user clicks the button
			handler:function(){
			login.getForm().submit({

				method:'POST', 

				success:function(){
							window.location = 'valider.action';
				},
				failure:function(form, action){
					if(action.failureType == 'server'){
						obj = Ext.util.JSON.decode(action.response.responseText);
						Ext.Msg.alert('Erreur d authentification !', obj.errors.reason);
					}else{
						Ext.Msg.alert('Warning!', 'Serveur authentication non disponible: ' + action.response.responseText);
					}
					login.getForm().reset();
				} 

			});
		}
		}]
	});

	login.render('login');

});
